package com.pepository.neo4j;

import com.model.neo4j.Person;
import com.model.vo.PersonPay;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

public interface PersonRepository extends Neo4jRepository<Person, Long> {

    Person findPeopleByName(String name);

    @Query("match(p:Person {name:$name})-[a:ACTED_IN]-(m:Movie) return p,a,m")
    Person getGraphByName(@Param("name") String name);

    @Query("match(p:Person{name:$name})-[a:ACTED_IN]-(m:Movie)" +
            "return " +
            "id(p) as id," +
            "p.name as name," +
            "sum(a.pay) as allPay," +
            "count(m) as movieCount"
    )
    PersonPay getPayInfoByName(@Param("name")String name);

//    @Modifying
//    @Query( "MATCH (p:Person{name:$name}) " +
//            "SET p: $tt " +
//            "return p"
//    )
//    Person addTableByName(@Param("tt") String table, @Param("name")String name);

}
